﻿@{
    Layout = null;
}

<link href="~/libs/layui-v2.9.21/layui-v2.9.21/layui/css/layui.css" rel="stylesheet" />

<form class="layui-form layui-form-pane" action="">

    <div class="layui-form-item">
        <label class="layui-form-label">委托人</label>
        <div class="layui-input-block">
            <input type="text" name="consignor" lay-verify="required" placeholder="请输入仓库编码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商品编码</label>
        <div class="layui-input-block">
            <input type="text" name="commodityCode" lay-verify="required" placeholder="请输入仓库名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="productName" placeholder="请输入位置" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">单位</label>
        <div class="layui-input-block">
            <select id="unit" name="unit">
                <option value="">请选择</option>
            </select>

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">产品类别</label>
        <div class="layui-input-block">
            <input type="text" name="productCategory" placeholder="请输入负责人" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">单层</label>
        <div class="layui-input-block">
            <input type="text" name="singleLayer" placeholder="请输入负责人" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">产品属性</label>
        <div class="layui-input-block">
            <input type="text" name="productAttribute" placeholder="请输入负责人" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">基础单位</label>
        <div class="layui-input-block">
            <select id="basicUnit" name="basicUnit">
                <option value="">请选择</option>
                <option value="1">厘米</option>
                <option value="2">米</option>
            </select>

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户商品编码</label>
        <div class="layui-input-block">
            <input type="text" name="customerCommodityCode" placeholder="请输入负责人" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">破损情况</label>
        <div class="layui-input-block">
            <input type="text" name="breaking" placeholder="请输入负责人" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="demo2">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>
<script src="~/libs/layui-v2.9.21/layui-v2.9.21/layui/layui.js"></script>
<script src="~/libs/jquery/jquery.js"></script>
<script>
    layui.use(['form'], function () {
      var form = layui.form;
      var layer = layui.layer;
              // 提交事件
              form.on('submit(demo2)', function (data) {
                console.log(data); // 当前容器的全部表单字段，名值对形式：{name: value}
                var field = data.field; // 获取表单字段值

                    $.ajax({
                                url:"/CommodityDetail/AddCommodityDetail",
                                data:field,
                                type:"post",
                                dataType:"json",
                                success:function(res){
                                    console.log(res)
                                    if(res>0)
                                    {
                                       alert("添加成功")
                                       // 刷新父页面表格
                                        parent.layui.table.reload('Table');
                                        // 关闭弹窗
                                        var index = parent.layer.getFrameIndex(window.name);
                                        parent.layer.close(index);
                                    }
                                    else
                                    {
                                        alert("添加失败")
                                    }
                                }
                            })

                return false; // 阻止默认 form 跳转
              });


               // 单位
          var unit = function(){
                $.ajax({
                    url: "/CommodityDetail/GetDictItemById",
                    type: "get",
                    dataType: "json",
                    data: { id: 1 },
                    success: function (res) {
                        console.log(res)
                        var data = res;
                        var html = "";
                        for (var i = 0; i < data.length; i++) {
                            html += "<option value='" + data[i].sortId + "'>" + data[i].dictItemName + "</option>";
                        }
                        $("#unit").html(html);
                        form.render('select');
                    }
                });
           }

           unit();
    });
</script> 